var idDiv = document.getElementById('idDivExpendable');


function addNewArticle()
{
	 $(idDiv).slideToggle(80, function()
	 	{

	 	});
}
function submitNewArticle($idUser)
{
	$placeLocation = document.getElementById('placelocation').value;
	$articleBody = document.getElementById('articlebody').value;
	
	var jqxhr = $.post("add_new_place.php", {title: $placeLocation,
											 article: $articleBody,
											 userId: $idUser})
				.done(function(data)
				{
					window.location.reload();
				});
											 
	addNewArticle();
}

function deleteArticle(idArticle)
{
	 bootbox.confirm("Are you sure you want to delete this article?", function(result)
	 {	
		if (result == true)
			var jqxhr = $.post("delete_article.php", {param1: idArticle})
			.done(function(data)
			{
				window.location.reload();
			});
	}); 
}

function deleteComment(idComment)
{
	bootbox.confirm("Are you sure you want to delete this comment?", function(result)
	 {
  		if (result == true)
			var jqxhr = $.post("delete_comment.php", {param1: idComment})
			.done(function(data)
			{
				window.location.reload();
			});
	 });
}

// MODIF USER
function submitModificationUser()
{
	$lastName = document.getElementById('lastname').value;
	$firstName = document.getElementById('firstName').value;
	$mail = document.getElementById('email').value;
	$dob = document.getElementById('dateofbirth').value;
	$password = document.getElementById('password').value;
	$confirmationPassword = document.getElementById('confirmpassword').value;
	$urlPicture = document.getElementById('pictureProfil').src;
	$errors = document.getElementById('errors').value;
	
	if ($lastName != "" && $firstName != "" && $mail != "" && $dob != "" &&
		$password != "" && $confirmationPassword != "")
	{
		if ($password != $confirmationPassword)
		{	
			alert("Two pass are not the same !");
			//$errors = 'The two passwords are not the same';
			return ;
		}
		var jqxhr = $.post("update_user_info.php", {param1: $lastName,
		param2: $firstName,
		param3: $mail,
		param4: $dob,
		param5: $password,
		param6: $urlPicture })
		.done(function(data)
			{
				window.location.reload();
			});
	}
	else
	{
		alert('Some information are wrong or missing.');
	}
}

function closeModificationUser()
{
	$('#fade, a.close').remove();
}

// Subscription
jQuery(function($){
    $('a.poplight').on('click', function() {
        var popID = $(this).data('rel');
        var popWidth = $(this).data('width');
        
        $('#' + popID).fadeIn().css({ 'width': popWidth}).prepend('<a href="#" class="close"><img src="http://sohtanaka.developpez.com/tutoriels/javascript/creez-fenetre-modale-avec-css-et-jquery/fichiers/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

	var popMargTop = ($('#' + popID).height() + 80) / 2;
	var popMargLeft = ($('#' + popID).width() + 80) / 2;

	$('#' + popID).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });
		
	$('body').append('<div id="fade"></div>');
	$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
	
	return false;
	});
	
	$('body').on('click', 'a.close, #fade', function() {
		$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  
	});
		
		return false;
	});
	
      $(".group1").colorbox({rel:'group1'});
      $(".group2").colorbox({rel:'group2', transition:"fade"});
      
      $("#click").click(function(){ 
      $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
      return false;
      });	
  });


